<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.css}">
    <script th:src="@{/webjars/jquery/1.11.1/jquery.js}"></script>
    <script th:src="@{/webjars/bootstrap/3.3.7/js/bootstrap.js}"></script>
</head>
<body>
<div class="container">
    <p th:if="${session.loginUser!=null}">欢迎你,
        <b th:text="|${session.loginUser.nickName}(${session.loginUser.username})${session.loginUser.role.name}|"></b>

        <a title="注销登陆" th:href="@{/logout}" class="btn btn-link">登出</a>
    </p>
    <p th:unless="${session.loginUser!=null}">欢迎你,
        <a class="btn btn-link" th:href="@{/login}">去登录</a>
    </p>

    <h1>折扣列表</h1>
    <div class="text-right" th:if="${session.loginUser!=null and session.loginUser.role.name eq '管理员'}">
        <a class="btn btn-default" th:href="@{/discount/add}">添加折扣规则<span class="glyphicon glyphicon-plus"></span></a>
        <a class="btn btn-primary" th:href="@{/discount/list}">查看折扣规则</a>
    </div>
    <table class="table table-striped table-hover">
        <thead>
        <tr>
            <th>序号</th>
            <th>活动名称</th>
            <th>折扣类型</th>
            <th>图书类别</th>
            <th>折扣率</th>
            <th>活动期限</th>
            <th>开始日期</th>
            <th>结束日期</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <!--                使用themeleaf完成数据渲染-->
        <tr th:each="discount:${discountList}" th:object="${discount}">
            <td th:text="*{id}"></td>
            <td th:text="*{name}"></td>
            <td th:text="*{type}"></td>
            <td th:text="*{category.name}"></td>
            <td>
                <span th:text="*{rate*10}"></span><b class="text-primary">折</b>
            </td>
            <td th:text="*{dateLimit}?'是':'否'"></td>
            <td th:text="*{#dates.format(beginDate,'yyyy/MM/dd')}"></td>
            <td th:text="*{#dates.format(endDate,'yyyy-MM-dd')}"></td>
            <td>
                <a th:text="*{state}?'开启':'关闭'" th:class="*{state}?'text-success':'text-danger'"
                th:href="@{/discount/editState(id=*{id},state=*{!state})}"
                data-toggle="tooltip" data-placeholder="top" th:title="'点击按钮'+(*{!state}?'开启折扣':'关闭折扣')"></a>
            </td>
            <td>
                <a class="btn btn-danger btn-sm" th:href="@{/discount/delete(id=*{id})}">删除</a>
            </td>
        </tr>
        </tbody>
    </table>
</div>
<script type="text/javascript">
    $(function (){
        $("[data-toggle-tooltip]").tooltip();
    });
</script>
</body>
</html>